<?php

namespace App\Admin\Controllers;

use App\Enums\DefaultEnum;
use App\Models\BannerModel;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class BannerController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new BannerModel(), function (Grid $grid) {
            $grid->column('status')->switch();
            $grid->column('image')->image('',80);
            $grid->column('updated_at');

//            $grid->filter(function (Grid\Filter $filter) {
//                $filter->equal('id');
//
//            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new BannerModel(), function (Show $show) {
            $show->field('id');
            $show->field('status');
            $show->field('image');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new BannerModel(), function (Form $form) {
            $form->radio('status')->options(DefaultEnum::descriptions())->default(1);
            $form->image('image','图片')
                ->accept('png,jpeg,jpg')
                ->uniqueName()->autoUpload()->removable(false)->retainable()->saveFullUrl()->required();


        });
    }
}
